﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Transcend.DP3.Helper
{
	public class EscapeHelper
	{

		static readonly string sql_special_chars = "\'-*\\:\n\r\t&";

		public static string EscapeSqlKeywords(string value)
		{
			if (string.IsNullOrEmpty(value)) return string.Empty;
			StringBuilder buf = new StringBuilder(value.Length);
			foreach (char c in value)
			{
				if (c < 48 || (c > 57 & c < 65) || (c > 90 & c < 97) || (c > 122 & c < 128))
				{
					buf.Append("'||chr(");
					buf.Append((int)c);
					buf.Append(")||'");
				}
				else
				{
					buf.Append(c);
				}
				//if (sql_special_chars.IndexOf(c) != -1)
				//{
				//	buf.Append("'||chr(");
				//	buf.Append((int)c);
				//	buf.Append(")||'");
				//}
				//else
				//{
				//	buf.Append(c);
				//}
			}
			return buf.ToString();
		}
	}
}
